<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
	<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
	<script type="text/javascript">
	//获取 iframe 数量 
	var frLength = window.parent.frames.length;
	//父画面下标 
	var parentIndex = frLength-2;
	 $(function(){
		 
         // 表单验证
         $("#inputForm").validate();

         // 审核结果选择拒绝时，审核备注不为空
		  $(":radio").click(function(){
		    if($(this).val() == 1){
		    	//删除
		    	$("#auditAdvice").rules("remove","isEmptyTextArea");
		    }else{
		    	//添加
		    	$("#auditAdvice").rules("add",{isEmptyTextArea:true});
		    }
		  });
	 });
	 
	 // 判断备注是否为空
	 jQuery.validator.addMethod("isEmptyTextArea", function(value, element) {
	    if ($('#auditAdvice').val() != null && $('#auditAdvice').val() != 'null' && $('#auditAdvice').val().trim() != '') {
	    	return true;
	    }else{
	    	return false;
	    }
	 }, "<spring:message code="audit_no_accept_check_msg"/>"); 
	 
	    //保存方法
	    var saveForm={
	         t:null,
	         save:function(t){
	              this.t=t;
	              $(t).attr("disabled",true);
	              // 验证表单通过
	              if ($("#inputForm").valid()){

	                        // 获取需求单号的作业阶段(10 = 样品;20 = 单耗;30 = 报价;40 = 核料;合同  = 80)
	                        var pAuditRelateNo = '';
	                        if($("#auditRelateNo").val() != null && $('#auditRelateNo').val() != 'null' && $('#auditRelateNo').val().trim() != ''){
	                        	pAuditRelateNo = $("#auditRelateNo").val().substring(0,2);
	                        }
	                        var requestPath = '';
	                        if(pAuditRelateNo==10){
	                        	// 样品阶段
	                            requestPath = "${ctx}/specimen/production/saveAudit";
	                        }else if(pAuditRelateNo==30){
	                        	// 报价 
	                        	requestPath = "${ctx}/quotation/message/saveAudit";
	                        }else if(pAuditRelateNo==40){
	                        	// 物料 
	                        	requestPath = "${ctx}/customization/nuclearmaterial/saveAudit";
	                        }else if(pAuditRelateNo==80){
	                        	// 合同 
	                        	requestPath = "${ctx}/bigcargo/order/saveAudit";
	                        }else if(pAuditRelateNo==13){
	                        	// 采购合同 
	                        	requestPath = "${ctx}/purchase/contract/saveAudit";
	                        }else if(pAuditRelateNo==11){
	                        	// 采购预付款
	                        	requestPath = "${ctx}/purchase/advance/saveAudit";
	                        }else if(pAuditRelateNo==12){
	                        	// 外发合同 
	                        	requestPath = "${ctx}/putting/contract/saveAudit";
	                        }else if(pAuditRelateNo=='PA'){
	                        	// 采购手册
	                        	requestPath = "${ctx}/customenchase/single/saveAudit";	
	                        }else if(pAuditRelateNo=='HA'){
	                        	// 采购手册
	                        	requestPath = "${ctx}/purchase/handbook/saveAudit";	
	                        }else if(pAuditRelateNo=='FB'){
	                        	// 采购手册
	                        	requestPath = "${ctx}/settlement/single/saveAudit";	
	                        }else{
	                        	requestPath = '';
	                        }
	                        if(requestPath == ''){
	                            // 选择物料款式过多！
	                            layer.msg('<spring:message code="audit_path_error"/>', {time:1000});
	                            $(t).attr("disabled",false);
	                            return;
	                        }
	            	  
	                        // 从表单获取数据信息
	                        var params = $("#inputForm").serialize();

	                        // 调用后台保存方法
	                        $.post(requestPath,params,function(result){
	                             // 提示信息
	                             tipParent(result.message);
	                             // 返回状态
	                             if(result.statusCode==STATUSCODEOK){
	                                
	                                // 父画面按钮制御
	                        		var radioVal=$('input:radio[name="auditResult"]:checked').val();
	                        		if(radioVal==1){
		                        		if(window.parent.frames[parentIndex].funBtnDisable && typeof(window.parent.frames[parentIndex].funBtnDisable) == "function"){
		                        			window.parent.frames[parentIndex].funBtnDisable();
		                        		}
	                        		}else{
		                        		if(window.parent.frames[parentIndex].funBtnEnable && typeof(window.parent.frames[parentIndex].funBtnEnable) == "function"){
		                        			window.parent.frames[parentIndex].funBtnEnable();
		                        		}
	                        		}
	                        		if(pAuditRelateNo!=13){
	                        			window.parent.frames[parentIndex].closeWin();
	                        		}else{
	                        			window.parent.frames[parentIndex].updateAlertStatus();
	                        		}
	                                // 刷新页面
	                        		window.parent.frames[0].searchListForm();
	                        		closeWin();
	                             }else{
	                            	 $(saveForm.t).attr("disabled",false);
	                             }
	                        },'json'); 
	              }else{
	            	  $(saveForm.t).attr("disabled",false);
	              } 
	         } 
	    }

    </script>
</head>
<body>
<div class="layerHeader clearfix">	   
     <p class="headerTitle"><spring:message code="audit_title"/></p>	
    <div class="headerButton clearfix">
        <!-- 审核未通过 -->
        <c:if test="${auditInfo.auditStatus eq 0}">
        	<button type="button" onclick="saveForm.save(this)"><spring:message code="btn_ok"/></button>
        </c:if>
        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<div class="tabBoxSm" >
  <div class="tabSm smOrderBox">  
    <p class="title" style="margin-top:0;margin-bottom:5px;"><spring:message code="audit_resume_title"/></p>
    <div class="tableArea">
		<div class="tableScroll tableScrollSm" style="height:200px;">
			<table cellpadding="0" class="tableHead">
	            <thead>
	            <tr>
	            	<th><p class="width-95px"><spring:message code="audit_list_user"/></p></th>
	                <th><p class="width-95px"><spring:message code="audit_list_status"/></p></th>
	                <th><p style="width:400px;"><spring:message code="audit_list_remark"/></p></th>
	                <th><p class="width-100px"><spring:message code="audit_list_date"/></p></th>
	            </tr>
	            </thead>
	        </table>
	        <table cellpadding="0" class="tableBody">
	        <c:if test="${not empty auditInfo.auditList}" >
	            <tbody>
	            <c:forEach items="${auditInfo.auditList}" var="audit">
	            <tr>
	            	<td><p class="width-95px">${audit.createBy.firstName}${audit.createBy.lastName}</p></td>
	                <td><p class="width-95px">
	                    <c:if test="${audit.auditResult eq 1}" ><spring:message code="audit_list_status_yes"/></c:if>
                        <c:if test="${audit.auditResult eq 0}" ><spring:message code="audit_list_status_no"/></c:if>
	                </p></td>
	                <td><p style="width:400px;">${audit.auditAdvice}</p></td>
	                <td><p class="width-100px"><fmt:formatDate value="${audit.auditDate}" pattern="yyyy-MM-dd HH:mm" /></p></td>
	            </tr>
	            </c:forEach>     
	            </tbody>
	        </c:if>    
	        </table>
	    </div>
    </div>
  <form id="inputForm"  method="post">
	<input type="hidden" id="auditPhaseCd" name="auditPhaseCd" value="${auditInfo.auditPhaseCd}">
	<input type="hidden" id="auditRelateId" name="auditRelateId" value="${auditInfo.auditRelateId}">
	<input type="hidden" id="auditRelateNo" name="auditRelateNo" value="${auditInfo.auditRelateNo}">
	<input type="hidden" id="sampleRequestStatus" name="sampleRequestStatus" value="${auditInfo.sampleRequestStatus}">
	<input type="hidden" id="sampleProductionStatus" name="sampleProductionStatus" value="${auditInfo.sampleProductionStatus}">
	<input type="hidden" id="sampleRequestId" name="sampleRequestId" value="${auditInfo.sampleRequestId}">
	<input type="hidden" id="version" name="version" value="${auditInfo.version}">
	
    <p class="title"><spring:message code="audit_edit_title"/></p>
    <p class="tit">${fns:getDictName(auditInfo.auditPhaseCd)}（${auditInfo.auditRelateNo}<c:if test="${not empty auditInfo.sizeCd}" >-${fns:getDictName(auditInfo.sizeCd)}</c:if>）<spring:message code="audit_edit_msg"/></p>	
    <div class="items clearfix">
        	<div class="col-50 clearfix">
                <p class="tit"><spring:message code="audit_edit_msg_result"/></p>
                <div class="labelBox">
                    <label>
                        <input name="auditResult" value="1" type="radio" checked><spring:message code="audit_list_status_yes"/>
                    </label>
                    <label>
                        <input id="auditResultNo" name="auditResult" value="0" type="radio"><spring:message code="audit_list_status_no"/>
                    </label>
                </div>
            </div>
    </div>
    <div class="items clearfix">
        	<div class="clearfix">
                <div class="tit"><spring:message code="audit_edit_remark"/></div>
                <textarea id="auditAdvice" name="auditAdvice" style="width:760px;height:110px;"></textarea>
            </div>
    </div>
   </div> 
 </div>
 </form>
</body>
</html>
